C++ Program Using Pointers

I want to express my sincere thanks to Anita Millspaugh and Dr. Swamy Narashammy for teaching me C++ language for three semesters.
 

This next page is only for programmers. It will not make sense if you are not into programming...sorry?
 

//Program: Adds, Removes, Single Display, All Display a list of
//         students using pointers.
//Author: Esteban Cazarez.
//Profr. Swammy Narashammy.
//Date: 8/11/97 DEVRY INSTITUTE OF TECHNOLOGY.
//Semester: Spring 97'.
//NOTE: It can work in arrays too if you delete the remarks.
//      You will have to fix the pointers to arrays.
#include <iostream.h> //Includes istream.h & frstream.h
#include <string.h>   //For string functions
#include <conio.h>    //Console I/O for cout, cin, getche()
#define FALSE 0
#define TRUE 1
enum command_type {ADD, DISPLAY, REMOVE, SHOWALL, QUIT, ILLEGAL};
command_type get_user_command()
{
  char command[80];
  cout << "Enter [A(dd),D(isplay),R(emove),S(howall),Q(uit)]:";
  cin >> command;
  switch(*command)
  {case 'a':case 'A':return(ADD);
  case 'd':case 'D':return(DISPLAY);
  case 'r':case 'R':return(REMOVE);
  case 's':case 'S':return(SHOWALL);
  case 'q':case 'Q':return(QUIT);
  default:return(ILLEGAL);}
}
int count=0; //Initialize count
class student
{
private:
  int age;
  char name[20];
  char address[20];
  char ssn[12];
public:
  char* get_name(){return name;}
  char* get_ssn(){return ssn;}
  char* get_address(){return address;}
  int get_age(){return age;}
  //int get_count(){return count;} //Optional!
  void add_student();
  void remove_student(char ssn[]){}
  //Not used in this example. Section reusable for Arrays.
  //void change_name(char nam[]){strcpy(name,nam);}
  //void change_ssn(char ss[]){strcpy(ssn,ss);}
  //void change_address(char add[]){strcpy(address,add);}
  //void change_age(int ag){age=ag;}
  student(int age,char name[20], char address[20], char ssn[12]);
  ~student(){count --;}  // Destructor
  student *next;         //Pointer
};
student *database;
student *temp;
//Construtor & body of the constructor below:
student::student(int ag,char nam[20], char add[30],char ss[12])
{
  strcpy(name,nam);
  strcpy(ssn,ss);
  strcpy(address,add);
  age=ag;
}
void add_student(int ag,char *nam, char *add, char *ss)
{
  student *temp = new student(ag,nam,add,ss);
  temp->next = database;
  database=temp;
}
void remove_student(char *ss)
{
 int found = FALSE;
 student *temp, *previous;
 temp=database, previous=NULL;
 
 while(!found && temp != NULL)
 
     if(strcmp(ss,temp->get_ssn())==0)
           found=TRUE;
     else
          {previous = temp;
          temp = temp->next;}
 
      if(found)
      {   if(previous==NULL)
          database = database->next;
      else
          {previous->next = temp->next;
          delete temp;}
       }
  else cout<<"Not found or deleted"<<endl;
}
void display_student(char *ss)
{
 int found = FALSE;
 student *temp, *previous;
 temp = database, previous =NULL;
 while(!found && temp != NULL)
  if(strcmp(ss,temp->get_ssn())==0)
     found = TRUE;
  else
     {previous = temp;
     temp = temp->next;}
  if(found)
     {if(previous == NULL)
     database=database->next;
  else
     {previous->next=temp->next;
      cout<<"Name: "<<temp->get_name()<<endl;
      cout<<"Address: "<<temp->get_address()<<endl;
      cout<<"SSN: "<<temp->get_ssn()<<endl;
      cout<<"Age: "<<temp->get_age()<<endl;
      cout<<"Currently number of objects: "<<count<<endl;
      delete temp;}
  }
 else
      cout<<"Not in the database. Please try again!"<<endl;
}
void showall_student()
{
 int found = FALSE;
 student *temp;
 student *previous;
 temp = database;
 previous = NULL;
 while(temp != NULL)
 {cout<<"Name: "<<temp->get_name()<<endl;
 cout<<"Address: "<<temp->get_address()<<endl;
 cout<<"SSN: "<<temp->get_ssn()<<endl;
 cout<<"Age: "<<temp->get_age()<<endl;
 cout<<"Total number of objects: "<<count<<endl;
 temp = temp->next;}
}
main()
{
 int ag,char nam[20],char add[20],char ss[12];
 command_type com;
 while((com = get_user_command())!=QUIT)
 {
 switch(com)
 {
  case ADD:
   cout<<"Student's &laquo;AGE:&raquo; "<<endl;
   cin>>ag;
   cout<<"Student's &laquo;NAME:&raquo; "<<endl;
   cin>>nam;
   cout<<"Students &laquo;ADDRESS:&raquo; "<<endl;
   cin>>add;
   cout<<"Student's &laquo;SSN:&raquo; "<<endl;
   cin>>ss;
   add_student(ag,nam,add,ss);
  break;
   case DISPLAY:
   cout<<"Enter the ssn to display:\n";
   cin>>ss;
   display_student(ss);
  break;
   case REMOVE:
   cout<<"Enter the ssn# to remove:\n";
   cin>>ss;
   remove_student(ss);
  break;
   case SHOWALL:
   showall_student();
   break;
  case ILLEGAL:
   cout << "** Illegal Command. Program Terminated! **"
        << endl;}
  }
}
~Back to main~